'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 4_study_tool_call_agnet.py
* @Time: 2025/11/5
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_community.tools import GoogleSerperRun
from langchain_community.tools.openai_dalle_image_generation import OpenAIDALLEImageGenerationTool
from langchain_community.utilities import GoogleSerperAPIWrapper
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, Field

dotenv.load_dotenv()
class GoogleSerperSchema(BaseModel):
    query:str = Field(description="执行谷歌搜索的查询语句")

google_serper = GoogleSerperRun(
    name = "google_serper",
    description = (
       "一个低成本的谷歌搜索工具"
       "当你想要回答有关问题的时候,可以调用该工具"
       "该工具的输入是搜索查询语句"),
        api_wrapper=GoogleSerperAPIWrapper()
)


dalle = OpenAIDALLEImageGenerationTool(
    name = "openai-dalle",
    api_wrapper=DallEAPIWrapper(model="dall-e-3")
)

tools = [google_serper, dalle]
prompt = ChatPromptTemplate.from_messages([
    ("system", "你一个功能强大的助手！"),
    ("placeholder", "{chat_history}"),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}"),
])
#创建模型
llm = ChatOpenAI(model="gpt-4o-mini")
agent = create_tool_calling_agent(
    prompt=prompt,
    llm=llm,
    tools=tools,
)

agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
print(agent_executor.invoke({"input":"台湾最近有什么 新闻"}))